<script setup>
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
const { currentRoute } = useRouter();
import { ElMessage } from 'element-plus'
const router = useRouter();
import { token } from "@/utils/api.js"


// 正式
const gettoken = async () => {
    window.sessionStorage.setItem('token', currentRoute.value.query.token);
    let res = await token(currentRoute.value.query.token)
    if (res.code == '200') {
        let data = res.data;
        let msg = {
            username: data.username,
            zhName: data.zhName,
            manageList: data.manageList,
            areaId: data.areaId,
            siteId: data.siteId
        }
        window.sessionStorage.setItem('usermsg', JSON.stringify(msg));
        window.sessionStorage.setItem('username', data.username);
        router.push({ path: '/animals' });
    } else {
        ElMessage({
            message: res.msg,
            type: 'warning',
        })
    }
}

// 测试
const login = async () => {
    // let msg = {
    //     username: "18235794676",
    //     zhName: "王曦",
    //     manageList: ["wulingshanSite"],
    //     areaId: "0000144",
    //     siteId: "wulingshanSite"
    // }
    // let msg = {
    //     username: "15011185072",
    //     zhName: "张北",
    //     manageList: ["a62c04302e4d4e5682b75b4e03fd4238"],
    //     areaId: "0000011",
    //     siteId: "a62c04302e4d4e5682b75b4e03fd4238"
    // }
    window.sessionStorage.setItem('usermsg', JSON.stringify(msg));
    router.push({ path: '/animals' });
}

onMounted(() => {
    // 正式
    if (currentRoute.value.query.token == undefined) {
        alert('您暂无权限查看，请登录后再查看')
    } else {
        gettoken();
    }
    //测试
    // login(); 
})

</script>
<template>
    <div>

    </div>
</template>
<style scoped></style>